package com.cn.servlet.news;

import com.cn.Dao.NewsinfoDao;
import com.cn.entity.NewsInfo;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
import java.util.List;

public class ShowPicServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        NewsinfoDao newsinfoDao = new NewsinfoDao();
        if (name != null) {
            try {
                NewsInfo newsInfo = newsinfoDao.findByName(name);
                byte[] pic = newsInfo.getPic();
                OutputStream outs = response.getOutputStream();
                if (pic != null) {
                    outs.write(pic);
                    outs.flush();
                    outs.close();
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
